package com.jxmcloud.business.cut.controller.app.gameConf;

import com.jxmcloud.business.cut.constants.CutApi;
import com.jxmcloud.business.cut.constants.CutSaveKey;
import com.jxmcloud.business.cut.model.database.DBUserLoginInfo;
import com.jxmcloud.business.cut.service.user.IUserLoginInfoService;
import com.jxmcloud.business.cut.service.user.IUserManagerService;
import com.jxmcloud.business.cut.vo.user.PlayerInfoVo;
import com.jxmcloud.business.cut.vo.user.UserFlowVo;
import com.xlcloud.platform.util.RUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Validated
@Slf4j
@RestController
@RequestMapping(CutApi.NAH_CUT_CONF)
public class GameConfController {
    @Autowired
    private IUserLoginInfoService userLoginInfoService;
    @Autowired
    private IUserManagerService userManagerService;
    /**
     * 修改用户当前步骤接口
     * @param account
     * @param stepId
     * @param preId
     * @return
     */
    @GetMapping("/updateUserStep")
    public String updateUserStep(String account, Integer stepId, Integer preId) {
        DBUserLoginInfo one = this.userLoginInfoService.lambdaQuery()
                .eq(DBUserLoginInfo::getAccount, account)  // 根据账号字段精确查询
                .one();
        if (one == null) {
            return RUtil.appFail("请先登录！");
        }
        PlayerInfoVo player = userManagerService.getUserInfo(one.getSessionKey());
        UserFlowVo flowInfo = player.getFlowInfo();
        flowInfo.setStepId(stepId);
        flowInfo.setPreId(preId);
        player.getMaster().getSaveList().add(CutSaveKey.USER_FLOW);
        // 刷新缓存信息
        userManagerService.refreshPlayerCache(player);
        return RUtil.appSuccess("成功");
    }
}
